package com.sxj.corejava.code08_常用类.内部类;

import com.sxj.corejava.code08_常用类.内部类.OuterThree.InnerThree;

/**
 * @author 石小俊
 */
public class Test03_静态内部类 {

    public static void main(String[] args) {
        // 在非外部类中实例化内部类
        OuterThree outer = new OuterThree();
        // 方式一:将外部类.内部类作为一个完整的类名
        OuterThree.InnerThree inner = new OuterThree.InnerThree();
        // 方式二:导包的时候将内部类所在的外部类也导入
        InnerThree innerThree = new InnerThree();

//        outer.show();
        innerThree.print();
    }

}

class OuterThree {
    private String name = "outer";
    private static int age = 20;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void show() {
        // 在外部类中实例化内部类,正常实例化即可
        InnerThree innerThree = new InnerThree();
        System.out.println(name);
        System.out.println(age);
        System.out.println(innerThree.name);
        System.out.println(innerThree.phone);
    }

    static class InnerThree {
        private String name = "inner";
        private String phone = "13812345678";

        public void print() {
            System.out.println(name);
            // 静态内部类只能访问静态的成员
            System.out.println(age);
            System.out.println(phone);
            OuterThree outerThree = new OuterThree();
            System.out.println(outerThree.name);
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }
    }

}